<?php
/**
* @version $Id: delete.php,v 1.0 2005/10/02 13:15:15 mic Exp $
* @package XfaQ - a frequently asked question component for Joomla! & Mambo CMS
* @copyright (C) 2005 mgfi.info
* @info info@mgfi.info http://www.mgfi.info
* @license GNU/GPL
* based in simplefaq 2.0.1 & glossary 1.4
*/

# Don't allow direct linking
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$id = mosGetParam( $_REQUEST, 'id','' );
$page = mosGetParam( $_REQUEST, 'page','1' );

global $my, $is_editor, $is_admin, $submit;

# Main Part of Subfunction
if ($is_editor){
	if ($submit) {
        $sql = 'DELETE FROM ' . $GLOBALS['mosConfig_dbprefix'] . 'xfaq WHERE id = \'' . $id . '\'';
        $database->setquery( $sql );
        $database->query();
        echo '<script> alert(\'' . _XFAQ_DELMESSAGE . '\'); document.location.href="index.php?option=com_xfaq&amp;task=display&amp;Itemid=' . $Itemid . '&amp;page=' . $page . '&amp;catid=' . $catid . '";</script>';
    } else {
        $query1 = 'SELECT * FROM ' . $GLOBALS['mosConfig_dbprefix'] . 'xfaq WHERE id = \'' . $id . '\'';
        $result1 = $database->setquery( $query1 );
        $row = $database->loadobjectlist( $result1 );
        $id = $row[0]->id;
        $name = $row[0]->name;
        $email = $row[0]->email;
        $location = $row[0]->location;
        $question = $row[0]->question;
        $homepage = $row[0]->homepage;
        $answer = $row[0]->answer;
        $date_created = $row[0]->date_created;
        $comment = $row[0]->comment;
        $edit = $row[0]->edit;
        $editdate = $row[0]->editdate;

        #Show the Original Entry
        $signtime = $date_created; ?>
        <table width="100%" border="0" cellspacing="1" cellpadding="4">
        	<tr>
        		<td width="30%" height="20" class="sectiontableheader"><?php echo _XFAQ_AUTHOR; ?></td>
        		<td width="70%" height="20" class="sectiontableheader"><?php echo _XFAQ_TERM; ?></td>
        	</tr>
        	<tr class="sectiontableentry1">
        		<td width="30%" valign="top">
        			<strong><?php echo $name; ?></strong>
        			<br />
        			<?php
        			if( $location <> '' ){ ?>
                        <br />
                        <span class="small"><?php echo _XFAQ_FROM . ' - ' . $location; ?></span>
                        <?php
                    }
        			if( $email <> '' ){ ?>
        				<a href="mailto:<?php echo $row1->email; ?>"><img src="components/com_xfaq/images/email.gif" alt="<?php echo $email; ?>" title="<?php echo $email; ?>" hspace="3" border="0" /></a>
        				<?php
        			}
        			if( $homepage <> '' ){ ?>
        				<a href="<?php echo $row1->homepage; ?>" target="_blank"><img src="components/com_xfaq/images/homepage.gif" alt="<?php echo $homepage; ?>" title="<?php echo $homepage; ?>" hspace="3" border="0" /></a>
        				<?php
        			}
        			echo $signtime; ?>
        		</td>
        		<?php
                $origtext = preg_replace( '/(\015\012)|(\015)|(\012)/', '&nbsp;<br />', $answer ); ?>
                <td width="70%" valign="top">
                	<span class="small"><?php echo $question; ?>
                		<hr />
                	</span>
                	<?php echo $origtext; ?>
                </td>
            </tr>
        </table>
        <form method="post" action="index.php?option=com_xfaq&amp;Itemid=<?php echo $Itemid; ?>&amp;task=delete&amp;id=<?php echo $id; ?>">
        	<input type="hidden" name="catid" value="<?php echo $catid; ?>" />
        	<input type="hidden" name="page" value="<?php echo $page; ?>" />
        	<input class="button" type="submit" name="submit" value="<?php echo _XFAQ_ADELETE; ?>" />
        </form>
        <p>
        	<a href="index.php?option=com_xfaq&amp;page=<?php echo $page; ?>&amp;Itemid=<?php echo $Itemid; ?>"><?php echo _XFAQ_BACK; ?></a>
        </p>
        <?php
	}
} else { ?>
	<p>
		<a href="index.php?option=com_xfaq&amp;page=<?php echo $page; ?>&amp;Itemid=<?php echo $Itemid; ?>"><?php echo _XFAQ_BACK; ?></a>
	</p>
	<?php
}
?>